package com.ybc.chinese.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.ybc.chinese.R;
import com.ybc.chinese.activity.ChineseSpecialActivity;
import com.ybc.chinese.activity.EnglistSpecialActivity;
import com.ybc.chinese.activity.MathSpecialActivity;
import com.ybc.chinese.activity.PolitySpecialActivity;
import com.ybc.chinese.adapter.SpecialAdapter;
import com.ybc.chinese.utils.CommonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * <p>专题<p/>
 * Created by Yubch on 17/2/18.
 */
public class SpecialFragment extends BaseFragment {
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.gv_special)
    GridView gvSpecial;

    private Context mCtx;
    private SpecialAdapter mAdapter;
    private List<String> datas = new ArrayList<>();

    public static SpecialFragment newInstance() {
        SpecialFragment specialFragment = new SpecialFragment();
        return specialFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mCtx = getActivity();
        View view = inflater.from(mCtx).inflate(R.layout.fragment_special, container, false);
        ButterKnife.bind(this, view);
        initView();
        initData();
        return view;
    }

    private void initData() {
        datas.add("高中语文");
        datas.add("高中数学");
        datas.add("高中英语");
        datas.add("高中政治");
        datas.add("高中历史");
        datas.add("高中地理");
        datas.add("高中物理");
        datas.add("高中化学");
        datas.add("高中生物");
        mAdapter.setDatas(datas);
    }

    private void initView() {
        tvTitle.setText(getString(R.string.college_special));
        mAdapter = new SpecialAdapter(mCtx);
        gvSpecial.setAdapter(mAdapter);
        gvSpecial.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0: //高中语文
                        Intent intent = new Intent(mCtx, ChineseSpecialActivity.class);
                        startActivity(intent);
                        break;
                    case 1: //高中数学
                        intent = new Intent(mCtx, MathSpecialActivity.class);
                        startActivity(intent);
                        break;
                    case 2: //高中英语
                        intent = new Intent(mCtx, EnglistSpecialActivity.class);
                        startActivity(intent);
                        break;
                    case 3: //高中政治
                        intent = new Intent(mCtx, PolitySpecialActivity.class);
                        startActivity(intent);
                        break;
                    default:
                        CommonUtil.showToast(mCtx, R.string.developing);
                        break;
                }
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
